package com.syz.mall.controller;

import com.syz.mall.pojo.Category;
import com.syz.mall.pojo.Collect;
import com.syz.mall.pojo.Product;
import com.syz.mall.service.ICategoryService;
import com.syz.mall.service.IProductService;
import com.syz.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @Autowired
    private IUserService userService;
    @Autowired
    private ICategoryService categoryService;
    @RequestMapping("/getProductListPage")
    public String getProductListPage(Integer id, Model model) {
        System.out.println("ProductController.getProductListPage");
        List<Product> list =  productService.selectByCategoryId(id);
        model.addAttribute("list", list);
        Category category=categoryService.selectById(id);
        model.addAttribute("categoryName",category.getName());
        List<Product> recommends=productService.selectLimit(8);
        model.addAttribute("recommends", recommends);
        return "item_sale_page";
    }


    @RequestMapping("/getProductDetailPage")
    public String getProductDetailPage(Integer id, Model model) {
        System.out.println("ProductController.getProductDetailPage");
        Product product = productService.selectById(id);
        model.addAttribute("product", product);

        Category category=categoryService.selectById(product.getCategoryId());
        model.addAttribute("categoryName",category.getName());
        model.addAttribute("categoryId",category.getId());

        List<Product> recommends=productService.selectLimit(6);
        model.addAttribute("recommends", recommends);
        return "item_show";
    }

}
